// 从2025年1月1日起，男职工和原法定退休年龄为五十五周岁的女职工，法定退休年龄每四个月延迟一个月，分别逐步延迟至六十三周岁和五十八周岁
// 原法定退休年龄为五十周岁的女职工，法定退休年龄每二个月延迟一个月，逐步延迟至五十五周岁。

use std::str::FromStr;

pub fn retire_time(time: &str, tp: &str) -> String {
    let time: Vec<_> = time.split('-').collect();
    let y = u64::from_str(time[0]).unwrap();
    let m = u64::from_str(time[1]).unwrap();
    // 政策变改动这里
    let (t, max_t, round) = match tp {
        "原法定退休年龄55周岁女职工" => (55, 58, 4),
        "原法定退休年龄50周岁女职工" => (50, 55, 2),
        _ => (60, 63, 4),
    };
    let (ny, nm, addition) = cul_retire(y, m, t, max_t, round);
    let age = ((ny - y) as f64) + ((nm as f64) - (m as f64)) / 12f64;
    let age = match age.fract() == 0.0 {
        true => format!("{}", age.trunc()),
        false => format!("{:.2}", age),
    };
    format!("{}-{:02},{},{}", ny, nm, age, addition)
}

fn cul_retire(y: u64, m: u64, t: u64, max_t: u64, round: u64) -> (u64, u64, u64) {
    let ny = y + t;
    if ny < 2025 {
        return (ny, m, 0);
    }
    let over_m = (ny - 2025) * 12 + m;
    let mut addition = (over_m + round - 1) / round;
    let max_m = (max_t - t) * 12;
    if addition > max_m {
        addition = max_m;
    }
    let nm = m + addition;
    (ny + (nm - 1) / 12, (nm - 1) % 12 + 1, addition)
}
